#include "Col.ph"
#ifdef __GNUG__
#pragma implementation
#endif

#include "Progress.h"

#include "Class.h"
#include "Timer.h"

static Progress dfltProgress;
Progress *gProgress= &dfltProgress;

//---- ProgressTimeoutHandler --------------------------------------------------

class ProgressTimeoutHandler : public Timer {
	Progress *progress;
public:
	ProgressTimeoutHandler(Progress *pi) : Timer(700, eAsync)
		{ progress= pi; }
	bool Notify()
		{ progress->timeout= TRUE; return FALSE; }
};

//---- Progress ----------------------------------------------------------------

NewMetaImpl0(Progress, Object);

bool Progress::inProgress;

Progress::Progress()
{
}

void Progress::Start(const char *message, long mx, bool enableabort)
{
	if (inProgress)
		Stop();
	inProgress= TRUE;
	aborted= FALSE;
	curr= 0;
	SetMax(mx);
	SetMessage(message);
	DoEnableAbort(enableabort);
	DoSetUp();
	alarmhandler= new ProgressTimeoutHandler(this);
}

void Progress::EnableAbort(bool b)
{
	DoEnableAbort(b);
}

void Progress::SetMessage(const char *msg)
{
	DoSetMessage(msg);
}

bool Progress::Stop()
{
	SafeDelete(alarmhandler);
	DoAbort(TRUE);
	timeout= inProgress= FALSE;
	return aborted;
}

void Progress::Abort()
{
	SafeDelete(alarmhandler);
	DoAbort(FALSE);
	aborted= TRUE;
	timeout= inProgress= FALSE;
}

//---- subclass responsibility

void Progress::DoSetUp()
{
}

void Progress::DoSetMessage(const char*)
{
}

bool Progress::DoSetVal()
{
	return FALSE;
}

void Progress::DoAbort(bool)
{
}

void Progress::DoEnableAbort(bool)
{
}

